package com.cet.designpatterns.principle.ocp.improvement;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-08-27 17:08
 **/
public class Ocp {
    public static void main(String[] args) {
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Rectangle());
        graphicEditor.drawShape(new Circle());
        graphicEditor.drawShape(new Triangle());
        graphicEditor.drawShape(new ExtensionalShape());
    }
}

/**
 * 这是一个绘图的工具诶【使用方】
 */
class GraphicEditor {
    public void drawShape(Shape s) {
        s.draw();
    }
}

abstract class Shape {
    public abstract void draw();
}

class Rectangle extends Shape {

    @Override
    public void draw() {
        System.out.println("绘制矩形");
    }
}

class Circle extends Shape {

    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}

class Triangle extends Shape {

    @Override
    public void draw() {
        System.out.println("绘制三角形");
    }
}

class ExtensionalShape extends Shape {
    @Override
    public void draw() {
        System.out.println("扩展图形");
    }
}
